package test.utility;

import java. text. ParseException;
import java. text. SimpleDateFormat;
import java. util. Date;
/*
 * @ 2023-04-21
 * 常用的静态方法，例如数据类型转换等等
 */
public class Utility {
    static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //默认时间格式
    static String MIN_DATE = "1900-01-01 00:00:00";
    static String MAX_DATE = "2100-12-31 23:59:59";
    static String NULL_String = "NULL";

    public static String stringToHexString(String value) {
        String rt = "0x";
        if (value == null || value.length() == 0) {
            return NULL_String;
        }
        for (int i = 0; i < value.length(); i++) {
            int j = value.charAt(i);
            rt += Integer.toHexString(j);
        }
        return rt;
    }

    public static String CurrentTime() {
        return dateFormat.format(new Date());
    }

    public static String longToTime(long value) {
        return dateFormat.format(new Date(value));
    }

    public static long getMinTimestamp() {
        long value = new Date().getTime();
        try {
            value = dateFormat.parse(MIN_DATE).getTime();
        } catch (ParseException e) {
// TODO Auto-generated catch block
        }
        return value;
    }


    public static long getMaxTimestamp() {
        long value = new Date().getTime();
        try {
            value = dateFormat.parse(MAX_DATE).getTime();
        } catch (ParseException e) {
// TODO Auto-generated catch block
        }
        return value;
    }

    public static synchronized void output(String message) {
        System.out.println(message);
    }

    public static String execMsToS(long exectime) {
        return String.format("%.3f", exectime / 1000.00);
    }
}
